using UnityEngine;

public class Obstacle : MoveableObject
{    
    private static ObstacleGapNull obstacleGapNull = new ObstacleGapNull();
    private ObstacleGap obstacleGap = obstacleGapNull;
    private ObstacleReposition obstacleReposition;
    private ObstacleModel obstacleModel;

    public bool hasPassedTheGap()
    {
        return obstacleGap.hasPassedTheGap();
    }

    public void reset()
    {
        if (!isActive())
        {
            active();
            obstacleModel = DAL.Instance.createObstacleModel();            
        }            
        
        obstacleReposition = new ObstacleReposition(this, obstacleModel.MinY, obstacleModel.MaxY);
        obstacleGap = new ObstacleGap(this, obstacleModel.Gap);

        obstacleReposition.reset();
    }

    protected override void onComeToEndWay()
    {
        inactive();
    }

    protected override void initMoveBehaviour(MoveBehaviour moveBehaviour)
    {
        MoveParams moveParams = MoveParams.createFromObstacleParams(obstacleModel);
        moveBehaviour.init(moveParams);
    }

    protected override void bindEndX(ref float endWayX)
    {
        endWayX = obstacleModel.FinalX;
    }
}